package top.zhangjianyong.test.reptiles;

import lombok.extern.slf4j.Slf4j;
import top.zhangjianyong.utils.HtmlUtil;
import top.zhangjianyong.utils.JDBCUtil;
import top.zhangjianyong.utils.ReptileContent;
import top.zhangjianyong.utils.UrlUtil;

import java.sql.SQLException;
import java.util.*;

/**
 * @author ： zhangjianyong
 * @date ： 2023/4/20 6:37 PM
 */
@Slf4j
public class DelMain {

    public static void init() throws SQLException {
        String host = "rm-bp11xb28f141i1808ho.rwlb.rds.aliyuncs.com";
        String port = "3306";
        String dbname = "zhangjianyong_tools";
        String url = "jdbc:mysql://" + host + ":" + port + "/" + dbname + "?useSSL=false&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Hongkong";
        String user = "root";
        String password = "zhangjianyong@2023";
        JDBCUtil.init(url, user, password);
    }

    static String SQL_TMP = "DELETE from reptile_url where `host` ='HOST' and url not in('URL1','URL2','URL3','URL4') limit 10000";


    public static void main(String[] args) throws SQLException {
        init();
        List<String> list = new ArrayList<>();
        list.add("com.meiwenfeng");
        list.add("com.xllwsy");
        list.add("com.logozj");
        list.add("com.tengdawz");
        list.add("net.51pic");
        list.add("com.sdztll");
        list.add("cn.com.cunet");
        list.add("com.fob666");
        list.add("com.ysssyws");
        list.add("com.uibeglobal");
        list.add("com.hgj88");

        for (String rHost : list) {
            Map<String, Object> map = JDBCUtil.qryObj("select url from reptile_url where host =? limit 1", rHost);
            String url = (String) map.get("url");
            Set<String> urlSet = HtmlUtil.removeBlankUrl(Arrays.asList(url));
            ReptileContent.offerUrl(urlSet, UrlUtil.host(url));

            String host = UrlUtil.reveres(rHost);

            String sql = SQL_TMP.replace("HOST", rHost)
                    .replace("URL1", "http://" + host)
                    .replace("URL2", "https://" + host) ;

            while (true) {
                int update = JDBCUtil.update(sql);
                if (update == 0) break;
              //  JDBCUtil.commit();
                log.info("删除-{}", update);
            }
        }

    }
}
